/**
 * Created by vivienfanghua on 2016/7/26.
 */
var orm     = require('../../../../');
var messageCode=require('../../config/code');
var _       = require('lodash');
module.exports = {
    login:function(req,res){
        var user = req.session.get('user', {});
        req.session.set('user','Vivien');
        //return res.send('Login done!');
    },
    register:function(req,res){
        var params=_.pick(req.body, 'name', 'userpassword','qqopen','wxnopen');
        req.models.user.find({name:params.name},function(err,user){
            if(user.length==0){
                req.models.user.create(params,function (err, item) {
                    if(err) {
                        return res.send({message:messageCode.list_family_fail});
                    }
                    return res.send({message:messageCode.list_family_success,data:JSON.stringify(item)});
                });
                //return res.send("User is unique");
            }
            else {
                return res.send({message:messageCode.register_user_exists});
            }
        });
    },
    logout:function(req,res){
        res.send('Logout done!');
    }
}

